//
//  UserDefaultViewController.m
//  OCUI
//
//  Created by bus365-03 on 15/10/28.
//
//

#import "UserDefaultViewController.h"
#import "NSBaseBean.h"
@interface UserDefaultViewController ()

@end

@implementation UserDefaultViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
    [userDefault setObject:@"北京" forKey:@"city"];
    [userDefault synchronize];
    
    NSString *lastCity = [userDefault objectForKey:@"city"];
    NSLog(@"city:%@",lastCity);
    
    NSBaseBean * bean=[[NSBaseBean alloc]init];
    bean.code=@"123";
    bean.value=@"234";
    
    NSMutableData * mutableData=[NSMutableData data];
    
    NSKeyedArchiver *keyArchiver=[[NSKeyedArchiver alloc] initForWritingWithMutableData:mutableData];
    [keyArchiver encodeObject:bean forKey:@"bean"];
    [keyArchiver finishEncoding];
    [mutableData writeToFile:[self getDocumentPath] atomically:YES];
 
    
    // Do any additional setup after loading the view.
}
/* 获取Documents文件夹路径 */
- (NSString *)getDocumentPath {
    NSArray *documents = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentPath = documents[0];
    documentPath=[documentPath stringByAppendingPathComponent:@"bean.archiver"];
    return documentPath;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
